#include "precompiled.h"

#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <windows.h>

#include "CBDGenerator.h"
#include "CUtils.h"

const char * const kBaseCmd = "-b";
const char * const kPrivateKeyCmd = "-k";

int _tmain(int argc, _TCHAR* argv[])
{
	if( argc < 5 )
	{
		std::cout << "Usage: DBGenerator.exe -b new_base_filename -k private_key_PEM" << std::endl;
		return -1;
	}

	std::string base_filename;
	std::string private_key;

	if ( !strcmp(argv[1], kBaseCmd) ) base_filename = argv[2];
	else if ( !strcmp(argv[1], kPrivateKeyCmd) ) private_key = argv[2];

	if ( !strcmp(argv[3], kBaseCmd) ) base_filename = argv[4];
	else if ( !strcmp(argv[3], kPrivateKeyCmd) ) private_key = argv[4];

	CDBGenerator::generate( "DBGeneratorSignatures", base_filename.c_str() );

	if( CUtils::sign(base_filename.c_str(), private_key.c_str()) ) std::cout<<"\nThe base has been signed." << std::endl;
	else std::cout<<"\nThe signing of base has been failed." << std::endl;

	return 0;
}